import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/Login'
import Index from "@/components/Index";
import Welcome from "@/components/Welcome";
import ProductType from "@/components/ProductType";
import ProductList from "@/components/ProductList";
import Popular from "@/components/Popular";
import Rule from "@/components/Rule";
import CommissionList from "@/components/CommissionList";
import Order from "@/components/Order";
import Profit from "@/components/Profit";


Vue.use(Router);

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/',
      name: 'Index',
      component: Index,
      children:[
        {path:'/',component:Welcome},
        {path:'/product-type',component:ProductType},
        {path:'/product-list',component:ProductList},
        {path:'/popular',component:Popular},
        {path:'/rule',component:Rule},
        {path:'/commission-list',component:CommissionList},
        {path:'/order',component:Order},
        {path:'/profit',component:Profit}

      ]
    }
  ]
});
//全局守卫
router.beforeEach((to, from, next) => {
  let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
  if (userInfo) {
    next();
  } else {
    if (to.path === "/login") {
      next();
    } else {
      next("/login");
    }
  }
});
export default router
